package com.situ.mall.controller;

import com.situ.mall.pojo.User;
import com.situ.mall.pojo.query.UserQuery;
import com.situ.mall.service.IUserService;
import com.situ.mall.util.PageResult;
import com.situ.mall.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @RequestMapping("/list")
    public PageResult<User> list(UserQuery userQuery) {
        PageResult<User> pageResult = userService.list(userQuery);
        return pageResult;
    }

    @RequestMapping("/deleteById")
    public Result deleteById(Integer id) {
        userService.deleteById(id);
        return Result.ok("删除成功");
    }

    @RequestMapping("/deleteAll")
    public Result deleteAll(int[] ids) {
        userService.deleteAll(ids);
        return Result.ok("删除成功");
    }

    @RequestMapping("/add")
    public Result add(User user) {
        userService.add(user);
        return Result.ok("添加成功");
    }

    @RequestMapping("/selectById")
    public Result selectById(Integer id) {
        User user = userService.selectById(id);
        return Result.ok(user);
    }

    @RequestMapping("/update")
    public Result update(User user) {
        userService.update(user);
        return Result.ok("更新成功");
    }

    @RequestMapping("/updateStatus")
    public Result updateStatus(Integer id, Integer status) {
        userService.updateStatus(id, status);
        return Result.ok();
    }
}
